//
//  UIViewController+LSMethod.m
//  woi
//
//  Created by 中创 on 2020/3/26.
//  Copyright © 2020 中创-慧谷. All rights reserved.
//

#import "UIViewController+LSMethod.h"


@implementation UIViewController (LSMethod)

- (void)backToRootVC{
    UIViewController *presentingVc = self.presentingViewController;
    while (presentingVc.presentingViewController) { // 找到最底层那个present的控制器
        presentingVc = presentingVc.presentingViewController;
    }
    // 最初present的控制器dismiss后 之后所有的控制器都dismiss了
    if(presentingVc){
        NSLog(@"====%@", presentingVc.class);
        [presentingVc dismissViewControllerAnimated:YES completion:nil];
        if ([presentingVc isKindOfClass:[UINavigationController class]]) {
            UINavigationController * nav = (UINavigationController *)presentingVc;
            [nav popToRootViewControllerAnimated:YES];
        }
    }else{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

@end
